#!/usr/bin/env bash

IP="192.168.1.119 192.168.1.156"
#IP="192.168.134.134 192.168.134.135"

tar -zxvf /data/k8s/package/harbor-online-installer-v1.7.1.tgz -C /opt/

cd /opt/harbor

for harbor_ip in ${IP}
do
    echo "=========================================== ${harbor_ip} ==========================================="
    scp -r /opt/harbor/ root@${harbor_ip}:/opt/
    ssh root@${harbor_ip} "cp /opt/harbor/harbor.cfg{,.bak}"
done

for (( i=1; i<=2; i++ ))
do
    sed -e "s/reg.mydomain.com/`echo ${IP} | cut -d " " -f $i`/" /opt/harbor/harbor.cfg > /opt/harbor/harbor-`echo ${IP} | cut -d " " -f $i`.cfg
done

for harbor_ip in ${IP}
do
    echo "=========================================== ${harbor_ip} ==========================================="
    scp /opt/harbor/harbor-${harbor_ip}.cfg root@${harbor_ip}:/opt/harbor/harbor.cfg
    rm -rf /opt/harbor/harbor-${harbor_ip}.cfg
done

for harbor_ip in ${IP}
do
    echo "=========================================== ${harbor_ip} ==========================================="
    ssh root@${harbor_ip} "sh /opt/harbor/prepare"
    ssh root@${harbor_ip} "sh /opt/harbor/install.sh"
done
